<template>
  <div>
    <div v-if="questionList.length>0">
      <questionWaitingCard :questionItem="item" v-for="item in questionList" :key="item.id"></questionWaitingCard>
    </div>
    <div v-else>
      <a-empty/>
    </div>
  </div>
</template> 

<script>
import questionWaitingCard from "@/components/questionWaitingCard";
import {getRecommondQuestion,getInviteQuestion,getLastQuestion,getHotQuestion} from "@/api/request"
export default {
  name: 'questionWaiting',
  components: {
    questionWaitingCard
  },
  data(){
    return {
      questionList:[],
      userInfo:JSON.parse(localStorage.getItem('userInfo'))
    }
  },
  methods:{
    getRecommondQuestion(){
      
      getRecommondQuestion({
        "areas":this.userInfo.goodAreas
      }).then(res=>{
        if(res.data.status===0){
          this.questionList=res.data.data
        }
      })
    },
    getInviteQuestion(){
      getInviteQuestion().then(res=>{
        if(res.data.status===0){
          this.questionList=res.data.data
        }
      })
    },
    getLastQuestion(){
      getLastQuestion().then(res=>{
        if(res.data.status===0){
          this.questionList=res.data.data
        }
      })
    },
    getHotQuestion(){
      getHotQuestion().then(res=>{
        if(res.data.status===0){
          this.questionList=res.data.data
        }
      })
    }
  },
  watch:{
    $route(newValue){
      if(newValue.path==='/question/waiting'){
        if(newValue.query.type==='invite'){
          this.getInviteQuestion()
        }else if(newValue.query.type==='new'){
          this.getLastQuestion()
        }else if(newValue.query.type==='hot'){
          this.getHotQuestion()
        }else{
          this.getRecommondQuestion()
        }
      }
    },
    immediate:true
  }
}
</script>

<style scoped lang="less">

</style>
